package selcoursesys.service.impl;

/**
 * Created by Lpbdz on 2017/4/12.
 */
public class GetClassTime {
    public static String getClassTime(String ctime){
        String[] coursetime=ctime.split(",");
        int ctimelen=0;
        String cday="";     //上课星期
        int start=0,end=0,day=0;
        boolean flag=true;
        int count=1;
        for(int i=0;i<coursetime.length-1;i++){
            if(flag==true&&Integer.parseInt(coursetime[i+1])-Integer.parseInt(coursetime[i])==1){
                start=Integer.parseInt(coursetime[i])%10;
                day=Integer.parseInt(coursetime[i])/10;
                flag=false;
            }
            if(i==coursetime.length-2){
                if(Integer.parseInt(coursetime[i+1])%10==0){
                    end=10;
                    flag=true;
                }else{
                    end=Integer.parseInt(coursetime[i+1])%10;
                    flag=true;
                }
            }else if(Integer.parseInt(coursetime[i+1])-Integer.parseInt(coursetime[i])!=1){
                if(Integer.parseInt(coursetime[i])%10==0){
                    end=10;

                    flag=true;
                }else{
                    end=Integer.parseInt(coursetime[i])%10;
                    flag=true;
                }
            }
            if(flag==true){
                if(count==1){
                    cday+="星期"+(day+1)+"第"+start+"节到第"+end+"节";
                    count++;
                }
                else{
                    cday+="和"+"星期"+(day+1)+"第"+start+"节到第"+end+"节";
                }
            }
        }
        return cday;
    }
}
